package cn.tradewin.pmp.services.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.slf4j.Logger;

import cn.tradewin.common.model.RolesPerms;
import cn.tradewin.pmp.persist.client.TwdSecurityMapper;
import cn.tradewin.pmp.persist.client.UsersMapper;
import cn.tradewin.pmp.persist.model.Users;
import cn.tradewin.pmp.services.TwdSecurityService;

public class TwdSecurityServiceImpl implements TwdSecurityService {

	@Inject
	private Logger log;
	
	@Inject
	private SqlSessionFactory sqlSessionFactory;

	@Override
	public List<RolesPerms> getRolesPerms(String userid) {
		SqlSession session = null;
		try {
			session = sqlSessionFactory.openSession();
			TwdSecurityMapper mapper = session.getMapper(TwdSecurityMapper.class);
			List<RolesPerms> keys = mapper.selectRolesPerms(userid);
			return keys;
		} catch (Exception e) {
			log.debug(e.getMessage());
			throw new RuntimeException(e.getMessage());
		}
	}

	@Override
	public Users getUser(String userid) {
		SqlSession session = null;
		try {
			session = sqlSessionFactory.openSession();
			UsersMapper mapper = session.getMapper(UsersMapper.class);
			return mapper.selectByPrimaryKey(userid);
		} catch (Exception e) {
			log.debug(e.getMessage());
			throw new RuntimeException(e.getMessage());
		}
	}
}
